<?php
namespace BC\User\Grant\DB;

use BC\User\Grant\DB\GrantDB as DB;
use CPath\Data\Schema\IReadableSchema;
use CPath\Data\Schema\PDO\AbstractPDOTable as AbstractBase;
use CPath\Data\Schema\TableSchema;

/**
 * Class GrantUserTable
 * @table grant_user
 * @method GrantUserEntry fetch($whereColumn, $whereValue=null, $compare='=?', $selectColumns=null) fetch a GrantUserEntry instance
 * @method GrantUserEntry fetchOne($whereColumn, $whereValue=null, $compare='=?', $selectColumns=null) fetch a single GrantUserEntry
 * @method GrantUserEntry[] fetchAll($whereColumn, $whereValue=null, $compare='=?', $selectColumns=null) fetch an array of GrantUserEntry[]
 */
class GrantUserTable extends AbstractBase implements IReadableSchema {
	const TABLE_NAME = 'grant_user';
	const FETCH_CLASS = 'BC\\User\\Grant\\DB\\GrantUserEntry';
	const SELECT_COLUMNS = 'user_fingerprint, grant_fingerprint';
	const INSERT_COLUMNS = 'user_fingerprint, grant_fingerprint';
	/**

	 * @column CHAR(40)
	 * @index --name grant_user_lookup
	 * @unique --name grant_user_unique
	 * @select
	 * @insert
	 */
	const COLUMN_USER_FINGERPRINT = 'user_fingerprint';
	/**

	 * @column CHAR(40)
	 * @unique --name grant_user_unique
	 * @select
	 * @insert
	 */
	const COLUMN_GRANT_FINGERPRINT = 'grant_fingerprint';
	/**

	 * @index 
	 * @columns user_fingerprint
	 */
	const GRANT_USER_LOOKUP = 'grant_user_lookup';
	/**

	 * @index UNIQUE
	 * @columns user_fingerprint, grant_fingerprint
	 */
	const GRANT_USER_UNIQUE = 'grant_user_unique';

	function insertRow($user_fingerprint = null, $grant_fingerprint = null) { 
		return $this->insert(get_defined_vars());
	}

	function getSchema() { return new TableSchema('BC\\User\\Grant\\DB\\GrantUserEntry'); }

	private $mDB = null;
	function getDatabase() { return $this->mDB ?: $this->mDB = new DB(); }
}